<template>
  <scroll-view class="coupon-scroll" scroll-x="true">
    <view class="coupon-item" v-for="(item, index) in couponList" :key="index">
      <view class="coupon-content">
        <view class="coupon-info">
          <view class="price">
            <text v-if="item.discount_type != 1" :style="{ color: priceColor }"
              >￥</text
            >
            <text
              v-if="item.discount_type != 1"
              :style="{ color: priceColor }"
              >{{ item.sub_price }}</text
            >
            <text
              v-if="item.discount_type == 1"
              :style="{ color: priceColor, fontSize: '54rpx' }"
              >{{ item.discount }}折</text
            >
          </view>
          <view class="coupon-date" :style="{ color: infoColor }">{{
            item.expire_type != 1
              ? item.begintime + "-" + item.endtime
              : "领取" + item.expire_day + "天后失效"
          }}</view>
        </view>
        <view class="split-line"></view>
        <view
          class="coupon-receive"
          :class="item.is_receive == 1 ? 'has-receive' : ''"
          :style="{ borderColor: colorConfig.breakLine }"
          @click.stop="toGetCoupon(item)"
        >
          <view :style="{ color: btnColor }">{{ item.receive_content }}</view>
        </view>
      </view>
      <view class="coupon-bg" :style="{ background: colorConfig.bgColor }">
      </view>
    </view>
  </scroll-view>
</template>

<script>
export default {
  props: {
    propsData: {
      type: Object,
      default: () => {
        return {};
      },
    },
    couponList: {
      type: Array,
      default: [],
    },
  },

  computed: {
    colorConfig() {
      return this.propsData.params.colorConfig;
    },
    priceColor() {
      return this.propsData.params.colorConfig.priceColor;
    },
    infoColor() {
      return this.propsData.params.colorConfig.infoColor;
    },
    btnColor() {
      return this.propsData.params.colorConfig.btnColor;
    },
  },

  methods: {
    toGetCoupon(item) {
      if (item.is_receive != 0) return;
      this.$emit("toGetCoupon", { item });
    },
  },
};
</script>

<style scoped lang="scss">
.coupon-scroll {
  width: 93.6%;
  white-space: nowrap;
  margin: 0 auto;
  .coupon-item {
    width: 31.054%;
    position: relative;
    height: 32.534vw;
    display: inline-block;
    margin-right: 3.2vw;
    .coupon-content {
      width: 93.58%;
      height: 94.26%;
      position: absolute;
      left: 0;
      top: 0;
      z-index: 11;
      background: #ffffff;
      border: 1px solid #666666;
      .coupon-info {
        width: 100%;
        display: flex;
        justify-content: center;
        align-items: center;
        flex-direction: column;
        padding-top: 14.19%;

        .price {
          display: flex;
          align-items: baseline;
          line-height: 1;
          text:first-child {
            font-size: 32rpx;
            color: #ec2827;
          }
          text:last-child {
            color: #ec2827;
            font-size: 60rpx;
            font-weight: bold;
          }
        }
        .coupon-date {
          font-size: 24rpx;
          font-family: PingFang SC;
          font-weight: 400;
          color: #ffffff;
          margin-top: 24rpx;
          max-width: 90.33%;
          overflow: hidden;
          text-overflow: ellipsis;
          white-space: nowrap;
        }
      }
      .split-line {
        width: 20.59%;
        height: 1px;
        background-color: #cccccc;
        margin: 4.67% auto 0;
      }

      .coupon-receive {
        width: 83.48%;
        height: 24.59%;
        display: flex;
        justify-content: center;
        align-items: center;
        position: absolute;
        left: 8.26%;
        bottom: 0;
        view {
          font-size: 28rpx;
          color: #ffffff;
          font-family: PingFang SC;
          font-weight: 400;
        }
      }
      .has-receive {
        opacity: 0.6;
      }
    }
    .coupon-bg {
      width: 93.58%;
      height: 94.26%;
      position: absolute;
      right: 0;
      bottom: 0;
      z-index: 10;
    }
  }
  .coupon-item:last-child {
    margin-right: 0;
  }
}
</style>
